package com.fluidops.datacatalog.reltables.schemascore;

import java.util.Set;

import com.fluidops.datacatalog.reltables.acsDB.ACSDB;

public class ConsistencyScore {

	private ACSDB acsDB;
	
	private int singleQueryTries = 0;
	private int singleQueryHits = 0;
	
	private int comboQueryHits = 0;
	
	ConsistencyScore(ACSDB acsDB){
		this.acsDB = acsDB;
	}
	
	double consistencyScore(Set<String> schema1, String a2){
		double consistency = 0d;
		
		if(schema1.size() > 0){
			for(String a1 : schema1){
				consistency += consistencyScore(a1, a2);
			}
			consistency = consistency / schema1.size();
		}
		
		return consistency;
	}

	private double consistencyScore(String a1, String a2){
		double consistency = 0d;
	
		singleQueryTries++;
		double singleFrequency = this.acsDB.getSingleFrequency(a1);
		if(singleFrequency > 0){
			singleQueryHits++;
			double pairwiseFrequency = this.acsDB.getPairwiseFrequency(a1, a2);
			if(pairwiseFrequency > 0){
				comboQueryHits++;
			}
			consistency = pairwiseFrequency / singleFrequency; 
		}
		
		return consistency;
	}

	public int getSingleQueryTries() {
		return singleQueryTries;
	}

	public int getSingleQueryHits() {
		return singleQueryHits;
	}

	public int getComboQueryHits() {
		return comboQueryHits;
	}
	
}
